package compiler;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import javax.swing.UIManager;

public class Compiler {
	private Window window;
	private ArrayList<File> files = new ArrayList<File>();

	public void start() {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}

		window = new Window(this);
		window.create();

		compile();
	}

	public void addSourceFile(File f) {
		for (int i = 0; i < files.size(); i++) {
			if (f.getName().toLowerCase().equals(files.get(i).getName().toLowerCase())) {
				log("Theres already a source file named: " + f.getName());
			}
		}
		
		files.add(f);
	}
	
	public void removeSourceFile(File f) {
		if (files.contains(f)) {
			files.remove(f);
		} else {
			log("Cant remove file: not found");
		}
	}


	public void compile() {
		try {
			Process p = Runtime.getRuntime().exec("cmd");
			InputStream i = p.getInputStream();
			
			String c;
			while((c = ""+(char)i.read()) != null) {
				System.out.println(c);
			}
			
			i.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		Compiler c = new Compiler();
		c.start();
	}
	

	public static void log(String msg) {
		System.out.println(msg);
	}

	public static void exit(boolean error) {
		if (error)
			System.exit(1);
		else
			System.exit(0);
	}
}
